package org.mokusakura.domain;

import org.springframework.http.HttpStatus;

import java.io.Serializable;
import java.util.LinkedHashMap;
import java.util.Map;

public class Response implements Serializable {
    private final Map<String, Object> data;
    private Integer status;
    private String message;
    private String error;

    private Response() {
        message = "";
        data = new LinkedHashMap<>(0);
        status = 200;
    }

    public static Response build() {
        return new Response();
    }

    public String getError() {
        return error;
    }

    public Response error(String error) {
        this.error = error;
        return this;
    }

    public Integer getStatus() {
        return status;
    }

    public String getMessage() {
        return message;
    }

    public Map<String, Object> getData() {
        return data;
    }

    public Response status(HttpStatus status) {
        this.status = status == null ? HttpStatus.INTERNAL_SERVER_ERROR.value() : status.value();
        return this;

    }

    public Response data(String key, Object data) {
        if (data == null) {
            data = new LinkedHashMap<>(0);
        }
        this.data.put(key, data);
        return this;
    }

    public Response message(String message) {
        if (message == null) {
            message = "";
        }
        this.message = message;
        return this;
    }


}
